import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tailwindcss from '@tailwindcss/vite'
import path from 'path';
import AutoImport from "unplugin-auto-import/vite"
import { NaiveUiResolver } from "unplugin-vue-components/resolvers"
import Components from "unplugin-vue-components/vite"
import { TDesignResolver } from '@tdesign-vue-next/auto-import-resolver';


// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    tailwindcss(),
    AutoImport({
      imports: [
        'vue', {
          'naive-ui': [
            'useDialog',
            'useMessage',
            'useNotification',
            'useLoadingBar',
            'useInput',
            'useButton',
            'useModal',
            'useCard'
          ]
        }
      ],
      resolvers: [TDesignResolver({
        library: 'chat'
      })],
    }),
    Components({
      resolvers: [NaiveUiResolver(), TDesignResolver({
        library: 'chat'
      })]
    })
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src/"),
      "@views": path.resolve(__dirname, "src/views"),
      "@components": path.resolve(__dirname, "src/components"),
      "@store": path.resolve(__dirname, "src/store"),
      "@images": path.resolve(__dirname, "src/assets"),
      "@utils": path.resolve(__dirname, "src/utils")
    }
  },
  define: {
    global: "window"
  },
  server: {
    proxy: {
      '/ws': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        ws: true,
        rewrite: (path) => path.replace(/^\/ws/, '')
      },
      '/amap': {
        target: 'https://restapi.amap.com',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/amap/, '') // 重写路径，去掉 /amap 前缀
      },
      '/snow-stomp': {
        target: "http://localhost:8080",
        ws: true,
        changeOrigin: true
      }
    }
  }
});
